﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Model;
using BLL;
using BLL.教师操作BLL;

namespace NCRE学生考试端V1._0
{
    public class PushGrades
    {
        public void push()
        {
            #region 必传字段
            Score score1 = new Score();
            score1.ClassName = "二班";
            score1.ConfirmType = "0";
            score1.TemplateId = "9Y-jur5cSChkNukxwunopP5idROtxrUkU9OX9UdR36I";
            score1.EventName = "一级练习";
            //score1.UserId = FrmLogin.studentID;
            ScoreAdornEntity score = new ScoreAdornEntity();
            #endregion

            TypeSumFrationBll addScoreAdorn = new TypeSumFrationBll();
            QRcodeBLL qucode = new QRcodeBLL();
            //查询当天时间并且没有推送出去所有字段
            DataTable dt = addScoreAdorn.inquiryScoreAdorn(score);
            //查询当天人次练习模式下所有学生个数
            DataTable table = qucode.SelectScoreAdornAllday();

            //将每个人的成绩都推送出去的循环
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                #region 查询分数排名的方法——薛帅行——2018年12月18点32分                            
                QRcodeBLL studentscoreAdornbll = new QRcodeBLL();
                int a = 0;//用于赋值当前人次排名
                ScoreAdornEntity scoreAdornEntity = new ScoreAdornEntity();
                score.userId = Convert.ToString(dt.Rows[i]["userId"]);
                //按照学号查询成绩
                //查询该学生各项目考试成绩                
                scoreAdornEntity.userId = dt.Rows[i][0].ToString();
                //DataTable table = studentscoreAdornbll.SelectScoreAdornOrder(scoreAdornEntity);
                if (dt.Rows.Count != 0)
                {
                    //总分排名
                    Single sin = Convert.ToSingle(dt.Rows[i]["totalScore"]);
                    scoreAdornEntity.totalScore = sin;
                    //scoreAdornEntity.totalScore =Convert.ToString(dt.Rows[i]["totalScore"]).ToString();
                    DataTable dtorder = studentscoreAdornbll.SelectScoreAdornOrder(scoreAdornEntity);//查询当天比自己成绩大的信息
                    a = dtorder.Rows.Count + 1;  //第几名


                }
                else { }
                #endregion

                //score1.UserId = FrmLogin.studentID;
                score1.UserId = Convert.ToString(dt.Rows[i]["userId"]);
                score1.UserName = Convert.ToString(dt.Rows[i]["userName"]);
                score1.UserCode = Convert.ToString(dt.Rows[i]["userCode"]);
                score1.TotalScore = Convert.ToString(dt.Rows[i]["totalScore"]);
                score1.TotalScoreRanking = Convert.ToString(a);

                #region score1其他的信息注释
                //score1.MultipleChoiceRanking = Convert.ToString(dt.Rows[0]["multipleChoiceRanking"]);
                //score1.WindowsRanking = Convert.ToString(dt.Rows[0]["WindowsRanking"]);
                //score1.WordRanking = Convert.ToString(dt.Rows[0]["WordRanking"]);
                //score1.ExcelRanking = Convert.ToString(dt.Rows[0]["ExcelRanking"]);
                //score1.PPTRanking = Convert.ToString(dt.Rows[0]["PPTRanking"]);
                //score1.IERanking = Convert.ToString(dt.Rows[0]["IERanking"]);

                //content.IERanking = Convert.ToDouble(IE).ToString("0.0");
                //score1.EventName = "{\"考试成绩\": \"score1.TotalScore\",\"总成绩排名\": score1.TotalScoreRanking,\"选择题排名\": \"score1.MultipleChoiceRanking\",\"Windows题排名\": \"score1.WindowsRanking\",\"Word题排名\":\"score1.WordRanking\",\"Excel题排名\":\"score1.ExcelRankin\",\"PPT题排名\": \"score1.PPTRanking\",\"IE题排名\": \"score1.IERanking\"}";
                //score1.EventName = "{\"totalScore\":\"100\",\"totalScoreRanking\":\"20\",\"multipleChoiceRanking\":\"20\",\"windowsRanking\":\"20\",\"wordRanking\":\"20\",\"excelRanking\":\"20\",\"PPTRanking\":\"20\",\"IERanking\":\"20\"}";

                //{"totalScore":"100","totalScoreRanking":"20","multipleChoiceRanking":"20","windowsRanking":"20","wordRanking":"20","excelRanking":"20","PPTRanking":"20","IERanking":"20"};
                //score1.EventContent = 

                #endregion

                string b1 = table.Rows[0][0].ToString(); //用于将当天的练习人次赋值

                Content1 content = new Content1();

                content.TotalScore = Convert.ToDouble(dt.Rows[i]["totalScore"]).ToString("0.0");
                content.TotalScoreRanking = Convert.ToString(a) + ",  " + "当天练习:" + Convert.ToString(b1) + "人次 。";
                content.MultipleChoiceRanking = Convert.ToDouble(dt.Rows[i]["multipleChoeceRanking"]).ToString("0.0");  //保留小数点后两位
                content.WindowsRanking = Convert.ToDouble(dt.Rows[i]["WindowsRanking"]).ToString("0.0");
                content.WordRanking = Convert.ToDouble(dt.Rows[i]["WordRanking"]).ToString("0.0");
                content.ExcelRanking = Convert.ToDouble(dt.Rows[i]["ExcelRanking"]).ToString("0.0");
                content.PPTRanking = Convert.ToDouble(dt.Rows[i]["PPTRanking"]).ToString("0.0");
                content.IERanking = Convert.ToDouble(dt.Rows[i]["IERanking"]).ToString("0.0");


                #region 分项成绩合格与不合格判断——薛帅行——2018年12月22号08点55分
                string message;
                //string message1;
                //string message2;
                //string message3;
                //string message4;
                //string message5;
                //string message6;
                if (Convert.ToInt32(dt.Rows[0]["multipleChoeceRanking"]) > 12 && Convert.ToInt32(dt.Rows[0]["WordRanking"]) > 15 && Convert.ToInt32(dt.Rows[0]["ExcelRanking"]) > 15 && Convert.ToInt32(dt.Rows[0]["WindowsRanking"]) > 6 && Convert.ToInt32(dt.Rows[0]["IERanking"]) > 6 && Convert.ToInt32(dt.Rows[0]["PPTRanking"]) > 6)
                {
                    message = "测试非常优秀，但是不要骄傲!";
                }
                else
                {
                    message = "测试成绩还有更大的提升空间，请再接再励!";
                }
                //message1,message2,message3,message4,message5,message6还有更大的提升空间，请再接再厉!

                #endregion
                content.Content = message;
                score1.EventContent = content;

                string result = IRestful.RestfulAdd(new Resful.EndSerialize().Serialize1(score1));
                //将获取的数据反序列化
                LoginEntity loginEntity1 = new Resful.Serialize().Deserialize(result);
                UserData userdata1 = loginEntity1.loginModel;

                #region 修改推送字段改为已推送--白爱民--2018年12月26日13:06:14
                addScoreAdorn.UpdateScoreAdorn(score);
                #endregion


            }
        }

        public void CyclePush ()
        {
           
        }
    }
}
